package com.base.thread;

import java.util.List;


public class MonitorThread extends Thread{
	
	private List<SubThread> subThreadList;
	
	public MonitorThread() {
		super();
	}


	public void init(String threadName,List<SubThread> subThreadList) {
		this.setName(threadName);
		this.subThreadList = subThreadList;
	}


	@Override
	public void run() {
		
		while(true){
			for (int a = 0 ; a < subThreadList.size() ; a++ ) {
				SubThread subThread = subThreadList.get(a);
				if(subThread.hasMsg()){
					
					//线程假死
					if(!subThread.isAlive()){
						
						subThread.interrupt();
						
						SubThread newThread = new SubThread(subThread); 
						newThread.start();
						subThread = newThread;
						
						subThreadList.remove(a);
						subThreadList.add(newThread);
					}
					
					//线程锁定
					if(subThread.isLock()){
						subThread.weakUp();
					}
				}
				
			}
		}
		
	}


	
	
	
	
	
	
	
	
	
	
	
	
}
